<template>
  <a-form-model
    :ref="'comorbidity' + confirmType"
    :model="comorbidity"
    :label-col="formItemLayout.labelCol"
    :wrapper-col="formItemLayout.wrapperCol"
    labelAlign="left"
  >
    <a-form-model-item label="确诊情况">
      <a-radio-group v-model="comorbidity.hypertension">
        <a-radio :value="1"> 确诊有 </a-radio>
        <a-radio :value="2"> 确诊无 </a-radio>
        <a-radio :value="3"> 未确诊 </a-radio>
      </a-radio-group>
    </a-form-model-item>
    <div class="content" v-show="comorbidity.hypertension === 1">
      <a-divider />
      <a-form-model-item label="确诊日期">
        <a-date-picker
          :disabled-date="disabledDate"
          v-model="comorbidity.hypertensionDate"
          @change="onChange"
          :style="{ width: '200px' }"
        />
      </a-form-model-item>

      <a-form-model-item label="是否服用降压药物">
        <a-radio-group v-model="comorbidity.ifHypotensor">
          <a-radio :value="1"> 是 </a-radio>
          <a-radio :value="2"> 否 </a-radio>
        </a-radio-group>
      </a-form-model-item>

      <a-form-model-item label="高血压分级">
        <j-dict-select-tag
          v-model="comorbidity.hypertensionLevel"
          dictCode="pubDossierHypertensionLevel"
          style="width: 200px"
          placeholder="请选择其结果"
          :style="{ display: 'inline-block' }"
        />
      </a-form-model-item>
    </div>
    <a-form-model-item :wrapper-col="{ span: 12, offset: 10 }">
      <a-button type="primary" @click="save" :loading="saveLoading">保存</a-button>
      <a-popconfirm placement="topLeft" ok-text="是" cancel-text="否" @confirm="confirm">
        <template slot="title">
          <p>此操作代表你已完成了页面的填写，是否继续？</p>
        </template>
        <a-button type="primary" style="margin-left: 30px" :loading="saveLoading">确认完成</a-button>
      </a-popconfirm>
    </a-form-model-item>
  </a-form-model>
</template>

<script>
import moment from 'moment'

export default {
  name: 'HighBloodPressure',
  props: ['comorbidity'],
  data() {
    return {
      confirmType: 1,
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 4 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        }
      },
      saveLoading: false
    }
  },
  methods: {
    onChange(date, dateString) {
      console.log(date, dateString)
      this.comorbidity.hypertensionDate = this.comorbidity.hypertensionDate.format('YYYY-MM-DD hh:mm:ss')
      console.log(this.comorbidity.hypertensionDate)
    },
    disabledDate(current) {
      // Can not select days before today and today
      return current > moment().endOf('day')
    },
    save() {
      this.saveLoading = true
      this.$emit('save', this.confirmType)
    },
    confirm() {
      this.saveLoading = true
      this.$emit('confirm', this.confirmType)
    }
  }
}
</script>

<style lang="less" scoped></style>
